using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Recruiters_ResumeDetails : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            connectionString =
                 WebConfigurationManager.ConnectionStrings[
                   "RecruitVietnam"].ConnectionString;

            RegisterJavaScript();

            if (Session.Contents["rcuserid"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                
                string resumeID = "", jobID = "";
                resumeID = Request.QueryString.Get("resumeid");
                jobID = Request.QueryString.Get("jobid");
                if(jobID == null || jobID == "") jobID = "0";
                if (resumeID == null || resumeID == "") resumeID = "0";
                Literal36.Text = jobID;
                Literal35.Text = resumeID;
                if (!IsPostBack)
                {
                    ShowResumeByRecruiter(resumeID, jobID, "0");                    
                }
                if (Session["rcactivate"].ToString() == "False")
                {
                    btnContact.Enabled = false;
                    btnOK.Enabled = false;
                    literalError.Text = "<img border=0 src='/icons/warning.gif'>You can not contact candidate, <br>because this account is not approved by management team.";
                }
            }
        }
        catch (Exception ex)
        {
            literalError.Text = ex.Message;
        }
    }
    void RegisterJavaScript()
    {
        Common common = new Common();
        ClientScript.RegisterClientScriptBlock(
        this.GetType(), "openWindowResume",
        common.CreateScriptForPrint("Resume"));
        btnBack.Attributes.Add("onclick", "window.history.go(-1);return false;");
        btnCancel.Attributes.Add("onclick", "window.history.go(-1);return false;");
        btnPrint.Attributes.Add("onclick",
        "openWindowResume" +
        "('Resume',400,700);return false;");
    }
    void ShowResumeByRecruiter(
    string resumeID, string jobID, 
    string type)
    {
        literalJob.Text = jobID;
        literalResume.Text = resumeID;
        literalError.Text = "";   
        SqlServerProvider cls = new
        SqlServerProvider(connectionString);
        cls.CommandText = "SPViewResumeByRecruiter";
        cls.CommandType =
        CommandType.StoredProcedure;
        cls.ParameterCollection = new
        string[4] { "@JobID",  "@Type",
        "@ResumeID", "@RecruiterID"};
        cls.ValueCollection = new
        string[4] { jobID, type, resumeID, 
        Session.Contents["rcuserid"].ToString() };
        DataSet dataSet = cls.GetDataSet();
        if(dataSet.Tables.Count != 0)
        {
            DataTable dataTable = dataSet.Tables[0];
            if (dataTable.Rows.Count > 0)
            {
                ShowResume(dataTable.Rows[0]);
            }
            dataTable = dataSet.Tables[1];
            if (dataTable.Rows.Count > 0)
            {
                ShowPersonal(dataTable.Rows[0]);
            }
            dataTable = dataSet.Tables[2];
            if (dataTable.Rows.Count > 0)
            {
                ShowEducation(dataTable,
                ShowEducationHeader());
            }
            dataTable = dataSet.Tables[3];
            if (dataTable.Rows.Count > 0)
            {
                ShowExperience(dataTable,
                ShowExperienceHeader());
            }

            dataTable = dataSet.Tables[4];
            if (dataTable.Rows.Count > 0)
            {
                ShowSkill(dataTable.Rows[0]);
            }
            dataTable = dataSet.Tables[5];
            if (dataTable.Rows.Count > 0)
            {
                ShowOther(dataTable.Rows[0]);

            }
            btnOK.Visible = false;
            btnCancel.Visible = false;
         }
         else
         {
            this.Resume.Visible = false;
            btnPrint.Visible = false;
            btnSave.Visible = false;
            btnContact.Visible= false;
            btnBack.Visible = false;
            btnOK.Visible = true;
            btnCancel.Visible = true;
            literalError.Text = 
            "Please be minded clicking OK button,"+
            " <br>Your resume view quota will be"+
            " deducted by on. <br>Do you wish"+
            " to proceed?";
            CheckViewQuota(Session.Contents[
            "rcuserid"].ToString());
         }
    }
    void CheckViewQuota(string recruiterID)
    {
        RecruitVietnam recruitVietnam = new RecruitVietnam();
            recruitVietnam.ConnectionString = connectionString;
           int viewQuota = recruitVietnam.GetViewQuota(Session.Contents["rcuserid"].ToString());
           if(viewQuota <=0)
           {
                btnOK.Enabled = false;
                literalError.Text = "Your resume view quota is empty, <br>Please purchase Job or View to see resume details.";
           }
    }
    void ShowOther(DataRow dataRow)
    {
        Literal30.Text = dataRow["Strength"].ToString();
        Literal31.Text = dataRow["Weekness"].ToString();
        Literal32.Text = dataRow["Hobbies"].ToString();
        Literal33.Text = dataRow["Family"].ToString();
        Literal34.Text = dataRow["Reference"].ToString();
    }
    void ShowSkill(DataRow dataRow)
    {
        Literal25.Text = dataRow["Speed"].ToString();
        Literal26.Text = dataRow["Software"].ToString();
        Literal27.Text = "Speaking: " +
        dataRow["VNSpeaking"].ToString() +
        "<br>Reading: " +
        dataRow["VNReading"].ToString() +
        "<br>Listening: " +
        dataRow["VNListening"].ToString();
        Literal28.Text = "Speaking: " +
        dataRow["ENSpeaking"].ToString() +
        "<br>Reading: " +
        dataRow["ENReading"].ToString() +
        "<br>Listening: " +
        dataRow["ENListening"].ToString();
        Literal29.Text = dataRow["Description"].ToString();
    }
    void ShowPersonal(DataRow dataRow)
    {
        Literal11.Text = dataRow["FirstName"].ToString();
        Literal12.Text = dataRow["LastName"].ToString();
        Literal13.Text = dataRow["DOB"].ToString();
        Literal14.Text = dataRow["Gender"].ToString();
        Literal15.Text = dataRow["MaritalStatus"].ToString();
        Literal16.Text = dataRow["RaceName"].ToString();
        Literal17.Text = dataRow["Email"].ToString();
        Literal18.Text = dataRow["Address"].ToString();
        Literal19.Text = dataRow["Resident"].ToString();
        Literal20.Text = dataRow["ProvinceName"].ToString();
        Literal21.Text = dataRow["City"].ToString();
        Literal22.Text = dataRow["Telephone"].ToString();
        Literal23.Text = dataRow["Mobile"].ToString();
    }
    void ShowResume(DataRow dataRow)
    {
        literalObjective.Text = dataRow["Objective"].ToString();
        Literal0.Text = dataRow["JobPosition"].ToString();
        Literal1.Text = dataRow["JobCategoryName"].ToString();
        Literal2.Text = dataRow["JobIndustryName"].ToString();
        Literal3.Text = dataRow["City"].ToString();
        Literal4.Text = dataRow["ProvinceName"].ToString();
        Literal5.Text = dataRow["SalaryFrom"].ToString();
        Literal6.Text = dataRow["ContactEmail"].ToString();
        Literal7.Text = dataRow["ReadyRelocate"].ToString();
        Literal8.Text = dataRow["WorkingTypeName"].ToString();
        Literal9.Text = dataRow["ResumeAvailable"].ToString();
        Literal10.Text = dataRow["Description"].ToString();
        Literal24.Text = dataRow["ExperienceYear"].ToString();
    }
    Table ShowExperienceHeader()
    {
        Table table = new Table();
        table.BackColor = System.Drawing.Color.Black;
        table.BorderStyle = BorderStyle.None;
        table.BorderWidth = 0;
        table.CellPadding = 1;
        table.CellSpacing = 1;
        table.BorderColor = System.Drawing.Color.Black;
        table.Width = Unit.Percentage(100);
        table.GridLines = GridLines.Both;
        TableRow tableRow = new TableRow();
        tableRow.BackColor = System.Drawing.Color.White;
        TableCell tableCell = new TableCell();
        tableCell.Text = "Company";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Address";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Nationality";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Province Name";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "JobCategoryName";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "JobPosition";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Salary";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Start";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "End";
        tableRow.Cells.Add(tableCell);
        table.Rows.Add(tableRow);
        return table;
    }
    void ShowExperience(DataTable dataTable, Table table)
    {
        TableRow tableRow;
        TableCell tableCell;
        foreach (DataRow dataRow in dataTable.Rows)
        {
            int i = 0;
            string JobSummary = "";
            string JobDescription = "";
            tableRow = new TableRow();
            tableRow.BackColor = System.Drawing.Color.White;
            foreach (object obj in dataRow.ItemArray)
            {
                if (i >= dataRow.ItemArray.Length - 2)
                {
                    if (i == dataRow.ItemArray.Length - 2)
                    {
                        JobSummary = obj.ToString();
                    }
                    if (i == dataRow.ItemArray.Length - 1)
                    {
                        JobDescription = obj.ToString();
                        break;
                    }
                }
                else
                {
                    tableCell = new TableCell();
                    tableCell.Text = obj.ToString();
                    tableRow.Cells.Add(tableCell);
                }
                i++;
            }
            table.Rows.Add(tableRow);
            if (JobSummary != "" || JobDescription != "")
            {
                tableRow = new TableRow();
                tableRow.BackColor = System.Drawing.Color.White;
                tableCell = new TableCell();
                tableCell.ColumnSpan = 9;
                if (JobSummary != "")
                    tableCell.Text = "Job Summary: " + JobSummary;
                if (JobDescription != "")
                    tableCell.Text += "<br>Job Description: " + JobDescription;
                tableRow.Cells.Add(tableCell);
                table.Rows.Add(tableRow);
            }
        }
        panelExperience.Controls.Add(table);
    }

    Table ShowEducationHeader()
    {
        Table table = new Table();
        table.BackColor = System.Drawing.Color.Black;
        table.BorderStyle = BorderStyle.None;
        table.BorderWidth = 0;
        table.CellPadding = 1;
        table.CellSpacing = 1;
        table.BorderColor = System.Drawing.Color.Black;
        table.Width = Unit.Percentage(100);
        table.GridLines = GridLines.Both;
        TableRow tableRow = new TableRow();
        tableRow.BackColor = System.Drawing.Color.White;
        TableCell tableCell = new TableCell();
        tableCell.Text = "School";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Faculty";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Major";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Country";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Certificate";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Traning Mode";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Start";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Finish";
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableCell.Text = "Description";
        tableRow.Cells.Add(tableCell);
        table.Rows.Add(tableRow);
        return table;
    }
    void ShowEducation(DataTable dataTable, Table table)
    {
        TableRow tableRow;
        TableCell tableCell;
        foreach (DataRow dataRow in dataTable.Rows)
        {
            tableRow = new TableRow();
            tableRow.BackColor = System.Drawing.Color.White;
            foreach (object obj in dataRow.ItemArray)
            {
                tableCell = new TableCell();
                tableCell.Text = obj.ToString();
                tableRow.Cells.Add(tableCell);
            }

            table.Rows.Add(tableRow);
        }
        panelEducation.Controls.Add(table);
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
            btnOK.Visible = false;
            btnCancel.Visible = false;          
            this.Resume.Visible = true;
            btnSave.Visible = true;
            btnPrint.Visible = true;
            btnBack.Visible = true;
            btnContact.Visible = true;
            RecruitVietnam recruitVietnam = new RecruitVietnam();
            recruitVietnam.ConnectionString = connectionString;
            if(!recruitVietnam.UpdateJobViewBalance(Session.Contents["rcuserid"].ToString(), "1"))
                literalError.Text = recruitVietnam.ErrorMessage;
            else
                ShowResumeByRecruiter(Literal35.Text, Literal36.Text, "1");
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        RecruitVietnam recruitVietnam = new RecruitVietnam();
        recruitVietnam.ConnectionString = connectionString;
        if(!recruitVietnam.SaveResumes(Session.Contents["rcuserid"].ToString(), literalResume.Text, Literal0.Text))
            literalError.Text = recruitVietnam.ErrorMessage;
         
    }
}
